package SwordForOffer.Problem14;

public class MyReorder {
    public void order(int[] array) {
        if (array == null || array.length == 0 || array.length == 1){
            return;
        }
        int startIndex = 0;
        for (int i = 0;i < array.length;i++){

            if (isEven(array[i])){
                startIndex = i;
                for (int j = startIndex + 1;j < array.length;j++){
                    if (!isEven(array[j])){
                        int temp = array[startIndex];
                        array[startIndex] = array[j];
                        array[j] = temp;
                        break;
                    }
                    if (j == array.length - 1){
                        return;
                    }
                }
            }
        }
    }

    private boolean isEven(int i) {

        return i%2 == 0;
    }
}
